package com.yunlin.blecontroler;
/*
    ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ 
       Author   :  lixiaodaoaaa
       Date     :  2018/6/15
       Time     :  14:42
    ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
 */

import android.bluetooth.BluetoothDevice;

import com.yunlin.bean.BleDevice;

import java.util.List;

public class BleDeviceUtils{
    
    /**
     * @return 将原始的macaddress转化为16进制hex形式的macAddress
     * 举例输入： C4:FD:D5:FD:5D:C5
     * 输出： C4FDD5FD5DC5
     */
    public static String converRawMacToHexMacAddress(String rawMacAddress){
        return rawMacAddress.replace(" ", "").trim().replace(":", "");
    }
    
    
    /**
     * @return 将原始的macaddress转化为16进制hex形式的macAddress
     * 举例输入： C4:FD:D5:FD:5D:C5
     * 输出： C4FDD5FD5DC5
     */
    public static String converRawMacToHexMacAddress(BluetoothDevice device){
        return converRawMacToHexMacAddress(device.getAddress());
    }
    
    
    /**
     * 判断此设备是锁的设备
     *
     * @param deviceName
     * @return
     */
    public static boolean checkDeviceIsLockDevice(String deviceName){
        if (!deviceName.contains("-")) {
            return false;
        }
        int position=deviceName.indexOf("-");
        
        String fakeAddress=deviceName.trim().substring(position + 1, deviceName.length());
        if (fakeAddress.length() != 12) {
            return false;
        }
        return true;
    }
    
    
    public static int checkBleDeviceInListBleIndex(BleDevice bleDevice, List<BleDevice> bleDeviceList){
        int length=bleDeviceList.size();
        for (int j=0; j < length; j++) {
            if (bleDevice.getBluetoothDevice().getAddress().equals(bleDeviceList.get(j).getBluetoothDevice().getAddress())) {
                return j;
            }
        }
        return -1;
    }
    
}
